package com.bank.chat.service.impl;

import com.bank.chat.factory.MapperFactory;
import com.bank.chat.factory.VoFactory;
import com.bank.chat.mapper.ChatRecordMapper;
import com.bank.chat.service.ChatRecordService;
import com.bank.model.entity.ChatRecord;
import com.bank.model.vo.chat.ChatRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author callumEm
 * @version 1.0
 * @create 2023/4/15 10:43
 */
@Service
public class ChatRecordServiceImpl implements ChatRecordService {

    @Autowired
    MapperFactory mapperFactory;
    @Autowired
    VoFactory voFactory;

    public List<ChatRecordVo> queryChatRecords(Long userId,Long toId){
        QueryWrapper<ChatRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("from_id",userId);
        queryWrapper.eq("to_id",toId);
        queryWrapper.or();
        queryWrapper.eq("to_id",userId);
        queryWrapper.eq("from_id",toId);

        List<ChatRecord> chatRecords = mapperFactory.getChatRecordMapper().selectList(queryWrapper);
        List<ChatRecordVo> res = voFactory.getChatRecordVos(chatRecords,userId);
        return res;
    }
}
